package com.renjianbo.project.module.flowable.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.renjianbo.project.module.flowable.common.model.Query;
import com.renjianbo.project.module.flowable.common.model.R;
import com.renjianbo.project.module.flowable.common.util.Condition;
import com.renjianbo.project.module.flowable.domain.WfDeployForm;
import com.renjianbo.project.module.flowable.domain.WfForm;
import com.renjianbo.project.module.flowable.service.IWfDeployFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.renjianbo.project.module.flowable.service.IWfFormService;


/**
 * 流程表单Controller
 *
 * @author XuanXuan
 * @date 2021-04-03
 */
@RestController
@RequestMapping("/flowable/form")
public class WfFormController {
    @Autowired
    private IWfFormService sysFormService;

    @Autowired
    private IWfDeployFormService deployFormService;

    /**
     * 查询流程表单列表
     */
    @GetMapping("/list")
    public R<IPage<WfForm>> list(WfForm sysForm, Query query) {
            IPage<WfForm> pages = sysFormService.page(Condition.getPage(query), Condition.getQueryWrapper(sysForm));

        //List<SysForm> list = SysFormService.selectSysFormList(sysForm);
            return R.data(pages);
    }

    /**
     * 导出流程表单列表
     */
    /*@GetMapping("/export")
    public R export(SysForm sysForm) {
        List<SysForm> list = SysFormService.selectSysFormList(sysForm);
        ExcelUtil<SysForm> util = new ExcelUtil<SysForm>(SysForm.class);
        return util.exportExcel(list, "form");
    }*/

    /**
     * 获取流程表单详细信息
     */
    @GetMapping(value = "/{formId}")
    public R getInfo(@PathVariable("formId") Long formId) {
        return R.data(sysFormService.selectSysFormById(formId));
    }

    /**
     * 新增流程表单
     */
    @PostMapping
    public R add(@RequestBody WfForm sysForm) {
        return R.status(sysFormService.insertSysForm(sysForm)>0);
    }

    /**
     * 修改流程表单
     */
    @PutMapping
    public R edit(@RequestBody WfForm sysForm) {
        return R.status(sysFormService.updateSysForm(sysForm)>0);
    }

    /**
     * 删除流程表单
     */
    @DeleteMapping("/{formIds}")
    public R remove(@PathVariable Long[] formIds) {
        return R.status(sysFormService.deleteSysFormByIds(formIds)>0);
    }

    @PostMapping("/addDeployForm")
    public R addDeployForm(@RequestBody WfDeployForm deployForm) {
        return R.status(deployFormService.insertWfDeployForm(deployForm));
    }
}
